import axios from "axios";
import { Message } from 'element-ui';
const service = axios.create({
    baseURL: '/api',
    timeout: 5000
})
service.interceptors.request.use(config => {
    return config
}, error => {
    return Promise.reject(error)
})
// 响应拦截
service.interceptors.response.use(conf => {
    return conf.data
}, err => {
    // 默认值
    let code = 400
    let message = "网络错误"
    if (err.response) {
        // 如果有返回值，则报返回值的错误
        code = err.response.data.code
        message = err.response.data.message
    }
    Message({
        message: message,
        type: 'error'
    });
    console.log(err);

    return { code, message }
})
export function UserLogin(data) {
    return service({
        url: '/user/login',
        method: 'post',
        data: data
    })
}
// 登陆验证的接口
export function loginStatus() {
    return service({
        url: "user/login/status",
        method: "get",
    })
}
export function Department(params, page = 1) {
    return service({
        url: '/admin/department/page/' + page,
        method: 'get',
        params: params
    })
}
export function Departmentxg(params) {
    return service({
        url: '/admin/department/page/count',
        method: 'get',
        params: params
    })
}
export function addepartment(data) {
    return service({
        url: '/admin/department',
        method: 'post',
        data: data
    })
}
//0000
export function departmentNames() {
    return service({
        url: '/admin/department/names',
        method: 'get',
    })
}
// depar===shanchu
export function deleteDepartment(id) {
    return service({
        url: '/admin/department/' + id,
        method: 'delete',
    })
}
export function majorList(params, page = 1) {
    return service({
        url: "/admin/major/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}

// 专业管理 --- 页数
export function majorCount(params) {
    return service({
        url: "/admin/major/page/count",
        method: "get",
        // get传递参数 -- params
        params: params
    })
}

// 专业管理 --- 添加
export function majorAdd(data) {
    return service({
        url: "/admin/major",
        method: "post",
        data: data
    })
}

// 专业管理 --- 详情
export function majorDetail(id) {
    return service({
        url: "/admin/major/" + id,
        method: "get",
    })
}

// 专业管理 --- 编辑
export function majorEdit(data) {
    return service({
        url: "/admin/major",
        method: "put",
        data: data
    })
}
//11111
//课程修改---列表
export function SelectList(params, page = 1) {
    return service({
        url: "/admin/student/course/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}
//班级列表--

export function classList(params, page = 1) {
    return service({
        url: "/admin/class/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}
// 课程管理 --- 列表
export function courseList(params, page = 1) {
    return service({
        url: "/admin/course/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}


// 课程管理 --- 添加
export function courseAdd(data) {
    return service({
        url: "/admin/course",
        method: "post",
        data: data
    })
}



// 课程管理 --- 详情
export function courseDetail(id) {
    return service({
        url: "/admin/course/" + id,
        method: "get",
    })
}

// 课程管理 --- 编辑
export function courseEdit(data) {
    return service({
        url: "/admin/course",
        method: "put",
        data: data
    })
}
// 课程管理 --- yeshu
export function Coursexg(params) {
    return service({
        url: "/admin/course/page/count",
        method: "get",
        // get传递参数 -- params
        params: params
    })
}
// 课程管理 --- shanchu
export function deleteCourse(id) {
    return service({
        url: "/admin/course/" + id,
        method: "delete",
    })
}
// 管理员管理 --- 列表
export function adminList() {
    return service({
        url: "/admin/admin",
        method: "get",
    })
}
//管理员添加
export function adminAdd(data) {
    return service({
        url: "/admin/admin",
        method: "post",
        data: data
    })
}
//管理员删除
export function deleteAdmin(id) {
    return service({
        url: "/admin/admin/" + id,
        method: "delete",
    })
}



// 管理员管理 --- 详情
export function adminDetail(id) {
    return service({
        url: "/admin/admin/" + id,
        method: "get",
    })
}
//学生管理--列表
export function studentList(params, page = 1) {
    return service({
        url: "/admin/student/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}
//教师管理--列表
export function teacherList(params, page = 1) {
    return service({
        url: "/admin/teacher/page/" + page,
        method: "get",
        // get传递参数 -- params
        params: params
    })
}
// ===================教师端==============

export function scheduleList() {
    return service({
        url: "/teacher/timetable",
        method: "get",
    })
}

